package ihm.tool;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * Writing to a log file.
 * @date 2 avr. 2013
 * @author Guillaume Pocas & Jean-François Augé
 */
public class Logger {

	final static Charset ENCODING = StandardCharsets.UTF_8;

	/**
	 * Write a matrice into a file text.
	 * @param fileName
	 * @param text
	 * @param rows
	 * @param columns
	 * @throws IOException
	 */
	public static void write(String fileName, Object[][] text, int rows, int columns) throws IOException {
		Path path = Paths.get(fileName);
		BufferedWriter writer = Files.newBufferedWriter(path, ENCODING);
		for(int i=0; i<rows; i++) {
			for(int j=0; j<columns; j++)
				writer.write(text[i][j]+"\t");
			writer.newLine();
		}
	}
	
	
	// tests
	public static void write(String fileName, String text) throws IOException {
		BufferedWriter out = new BufferedWriter(new FileWriter(fileName));
        out.write(text);
        out.close();
	}
		
}
